package com.haierCamera.customapplication.ui.main;

import android.content.Intent;
import android.os.Bundle;

import com.haierCamera.customapplication.BaseActivity;
import com.haierCamera.customapplication.R;
import com.haierCamera.customapplication.api.vo.GetDeviceEntity;
import com.haierCamera.customapplication.databinding.HzklActivityDeviceListBinding;
import com.haierCamera.customapplication.ui.business.Business;
import com.haierCamera.customapplication.ui.custom.BaseListenerOnClik;

import java.util.List;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

public class HZKLCameraDeviceListActivity extends BaseActivity {
    HzklActivityDeviceListBinding binding;

    HZKLDeviceListAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = DataBindingUtil.setContentView(this, R.layout.hzkl_activity_device_list);
        binding.imgReturn.setOnClickListener((v)->{
            finish();
        });


        binding.rcv.setLayoutManager(new LinearLayoutManager(this));
        adapter = new HZKLDeviceListAdapter(this);
        binding.rcv.setAdapter(adapter);

        adapter.upDate(Business.getInstance().getmDeviceList());
        adapter.setOnItemOnClick(new BaseListenerOnClik() {
            @Override
            public void onClick(int position) {
                List<GetDeviceEntity> data = Business.getInstance().getmDeviceList();
                startActivity(new Intent(HZKLCameraDeviceListActivity.this
                        ,HZKLCameraDeviceDetailActivity.class)
                        .putExtra("accountDeviceId",data.get(position).accountDeviceId)
                        .putExtra("name",data.get(position).name)
                        .putExtra("sn",data.get(position).serialNumber)
                        .putExtra("sc",data.get(position).securityCode)
                        .putExtra("picture",data.get(position).picture));
            }
        });
    }
}
